package com.zmx.doctor.adapter;

import android.app.Activity;
import android.os.Handler;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.bumptech.glide.Glide;
import com.wang.adapters.adapter.BaseAdapterRvList;
import com.wang.adapters.base.BaseViewHolder;
import com.zmx.doctor.R;
import com.zmx.doctor.pojo.ExpertTeamDoctor;


import butterknife.BindView;
import butterknife.ButterKnife;
import de.hdodenhof.circleimageview.CircleImageView;

/**
 * 程序猿：胖胖祥
 * 时 间：2020/11/20  9:48
 * 功 能：
 */
public class ExpertTeamDoctorAdapter extends BaseAdapterRvList<ExpertTeamDoctorAdapter.ViewHolder, ExpertTeamDoctor> {

    private Integer logo;
    private Handler handler;

    public ExpertTeamDoctorAdapter(Activity activity,Integer logo,Handler handler) {
        super(activity);
        this.logo = logo;
        this.handler = handler;
    }



    @Override
    protected void onBindVH(ViewHolder holder, int listPosition, ExpertTeamDoctor expertTeamDoctor) {

        Glide.with(mActivity).load(expertTeamDoctor.getAvatar()).into(holder.teamDoctorHead);
        holder.teamDoctorNames.setText(expertTeamDoctor.getName());
        holder.teamDoctorTitle.setText(expertTeamDoctor.getTitle_name());
        holder.teamDoctorDepment.setText(expertTeamDoctor.getHosp_name()+" "+expertTeamDoctor.getClass_name());

        if (logo == 0){

            holder.button.setVisibility(View.GONE);

        }else{
            holder.button.setVisibility(View.VISIBLE);
        }

        holder.button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                Message message = handler.obtainMessage();
                message.obj = expertTeamDoctor.getMember_id();
                message.arg1 = listPosition;
                message.what = 2;
                handler.sendMessage(message);


            }
        });

    }

    @NonNull
    @Override
    protected ViewHolder onCreateVH(ViewGroup parent, LayoutInflater inflater) {

        ExpertTeamDoctorAdapter.ViewHolder holder = new ExpertTeamDoctorAdapter.ViewHolder(inflater.inflate(R.layout.adapter_expert_team_doctor, parent, false));
        return holder;

    }

    static class ViewHolder extends BaseViewHolder {

        @BindView(R.id.team_doctor_head)
        CircleImageView teamDoctorHead;
        @BindView(R.id.team_doctor_names)
        TextView teamDoctorNames;
        @BindView(R.id.team_doctor_title)
        TextView teamDoctorTitle;
        @BindView(R.id.team_doctor_depment)
        TextView teamDoctorDepment;
        @BindView(R.id.button)
        Button button;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }

    }


}
